<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        // 深复制1  JSON.parse(JSON.stringfy());
        let obj  = {
            arr: ['pink'],
            name: 'zhangzhang',
            ob: {
                age: 18
            }
        }

        // let obj2 = JSON.parse(JSON.stringify(obj));

        // obj.arr.push('blue');

        // 实现深复制方法
        Object.icktAssign = function(target) {
            // 循环参数值
            for(let i=0; i<arguments.length ; i++) {
                // 缓存每一个参数
                let obj = arguments[i];
                // 遍历obj
                for(let key in obj) {
                    // 判断属性值的类型
                    if(Array.isArray(obj[key])) {
                        // 是数组
                        target[key] = Object.icktAssign([], obj[key])
                    }else if(Object.prototype.toString.call(obj[key]) === '[Object object]') {
                        // 是对象
                        target[key] = Object.icktAssign({}, obj[key]);
                    }else {
                        target[key] = obj[key];
                    }
                }
            }
            return target;
        }

        let result = Object.icktAssign({}, obj);
        obj.arr.push('blue');

        console.log(obj);
        console.log(result);
    </script>
</body>
</html>